import time
from pprint import pprint

import icecream
import requests,urllib3


headers = {
    'authority': 'careers.tencent.com',
    'pragma': 'no-cache',
    'cache-control': 'no-cache',
    'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"',
    'accept': 'application/json, text/plain, */*',
    'sec-ch-ua-mobile': '?0',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36',
    'sec-fetch-site': 'same-origin',
    'sec-fetch-mode': 'cors',
    'sec-fetch-dest': 'empty',
    'referer': 'https://careers.tencent.com/search.html?keyword=C',
    'accept-language': 'zh-CN,zh;q=0.9',
    'cookie': 'loading=agree',
}

params = (
    ('timestamp', '1629429991320'),
    ('language', 'zh-cn'),
    ('type', 'Nationality,WorkPlace,OuterType,BG,PostAttr'),
)

response = requests.get('https://careers.tencent.com/tencentcareer/api/post/Query?timestamp=1629429991320&countryId=&cityId=&bgIds=&productId=&categoryId=&parentCategoryId=&attrId=&keyword=C&pageIndex=1&pageSize=10&language=zh-cn&area=cn',headers = headers,params = params)
time.sleep(1)
pprint(response.request.headers)
# data = response.json().get('Data').get('Posts')
# for i in data:
#     print(type(data))
#     print(type(i.get('RecruitPostName')))

#NB. Original query string below. It seems impossible to parse and
#reproduce query strings 100% accurately so the one below is given
#in case the reproduced version is not "correct".
# response = requests.get('https://careers.tencent.com/tencentcareer/api/data/GetMultiDictionary?timestamp=1629429991320&language=zh-cn&type=Nationality,WorkPlace,OuterType,BG,PostAttr', headers=headers)
